<?php
// 应用分组基类
namespace Admin\Controller;
use Think\Controller;
use Org\Util\Rbac;
class CommonController extends Controller {
	function _initialize() {
		IS_WIN ? C('DATA_CACHE_TYPE','file') : NULL; //本地环境使用文件缓存
		// 用户权限检查
		if (C('USER_AUTH_ON') && !in_array(MODULE_NAME, explode(',', C('NOT_AUTH_MODULE')))) {
			if (!RBAC::AccessDecision()) {
				//检查认证识别号
				if (!$_SESSION [C('USER_AUTH_KEY')]) redirect(PHP_FILE . C('USER_AUTH_GATEWAY')); //跳转到认证网关
				
				// 没有权限 抛出错误
				if (C('RBAC_ERROR_PAGE')) {// 定义权限错误页面
					redirect(C('RBAC_ERROR_PAGE'));
				} else {
					if (C('GUEST_AUTH_ON')) {
						$this->assign('jumpUrl', PHP_FILE . C('USER_AUTH_GATEWAY'));
					}
					// 提示错误信息
					$this->error(L('_VALID_ACCESS_'));
				}
			}
		}
	}

	/**
	 * DWZ 回调数据
	 * @internal 此方法会向DWZ前台提供JSON数据
	 * @access public
	 * @param string $message
	 * @param string $navTabId
	 * @param string $statusCode
	 * @param string $rel
	 * @param string $callbackType
	 * @param string $forwardUrl
	 * @since 2014-10-11 16:35:41
	 * @author FrankKung <kongfanjian@andlisoft.com>
	 */
	public function DwzCallback($message, $navTabId, $statusCode = "200", $rel, $callbackType, $forwardUrl ) {
		$navTabId = I('get.navTabId');
		$navTabId = empty($navTabId) ? CONTROLLER_NAME : $navTabId;
		$data = array(
			'statusCode'	=> $statusCode,
			'message'		=> $message,
			'navTabId'		=> $navTabId,
			'rel'			=> $rel,
			'callbackType'	=> $callbackType,
			'forwardUrl'	=> $forwardUrl,
			);
		$this->ajaxReturn($data);
	}

	/**
	 * [可继承]禁用操作
	 * @internal 此方法会执行Model中的禁用方法
	 * @access public
	 * @since 2014-10-11 18:28:05
	 * @author FrankKung <kongfanjian@andlisoft.com>
	 */
	public function forbid() {
		$Model = D(CONTROLLER_NAME);
		$map['id'] = I("get.id");
		$ret = $Model->forbid($map);
		if ($list !== false) {
			$this->DwzCallback('状态禁用成功');
		} else {
			$this->DwzCallback('状态禁用失败！','',300);
		}
	}

	/**
	 * [可继承]恢复操作
	 * @internal 此方法会执行Model中的恢复方法
	 * @access public
	 * @since 2014-10-11 18:48:38
	 * @author FrankKung <kongfanjian@andlisoft.com>
	 */
	public function resume() {
		$Model = D(CONTROLLER_NAME);
		$map['id'] = I("get.id");
		$ret = $Model->resume($map);
		if ($list !== false) {
			$this->DwzCallback('状态恢复成功');
		} else {
			$this->DwzCallback('状态恢复失败！','',300);
		}
	}

	/**
	 * 验证码检测
	 * @internal 此方法用于检测输入的验证码是否正确
	 * @access public
	 * @param string $code 验证码字符串
	 * @since 2014-10-11 12:15:41
	 * @author FrankKung <kongfanjian@andlisoft.com>
	 */
	public function check_verify($code) {
		$verify = new \Think\Verify();
		return $verify->check($code);
	}

}